package com.sh.etcd;


import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.kv.GetResponse;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Etcd 注册中心
 */
public class EtcdRegistry{
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Client client = Client.builder().endpoints("http://127.0.0.1:2379").build();
        KV kvClient = client.getKVClient();
        ByteSequence key = ByteSequence.from("hello".getBytes());
        ByteSequence value = ByteSequence.from("world！！！！！！！！！！！".getBytes());
        kvClient.put(key, value).get();

        CompletableFuture<GetResponse> getResponseCompletableFuture = kvClient.get(key);
        GetResponse getResponse = getResponseCompletableFuture.get();
        System.out.println(getResponse.getKvs().get(0).toString());
//        kvClient.delete(key).get();


    }
}